print("Hello lua")

local function test(a)
	if a == 2 then
		error("test error")
	end

	return true
end

local ok, ret = pcall(test, 1)
print(ok, ret)

local ok, ret = pcall(test, 2)
print(ok, ret)


local function msghander(msg)
	print(msg)
	print(debug.traceback())
end

local ok, ret = xpcall(test, msghander, 1)
print(ok, ret)

local ok, ret = xpcall(test, msghander, 2)
print(ok, ret)

local mt = {
	__len = function(t)
		local n = 0
		for k, v in pairs(t) do 
			n = n + 1
		end
		return n
	end,

	__call = function(t, a1)
		return a1
	end
}

local t = {a = 1, b = "s", c = "ss", d = 1}
setmetatable(t, mt)
print(#t)
print(t("hello world"))

local t = {1, 2, 3, 5}
print(#t)

for k, v in pairs(debug.getregistry()) do 
    print(k, v, type(v)) 
end


print("path:", package.path)
print("cpath:", package.cpath)

print("=====================")

for k, v in pairs(_G) do
	print(k, v)
end

print(select(1,...))


print(_ENV)

print("=====================")
for k, v in pairs(package.searchers) do
	print(k, v)
end
